/*
 * Copyright 2009-2012 Prime Teknoloji.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.snifferx.view;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import org.primefaces.model.menu.DefaultMenuItem;
import org.primefaces.model.menu.DefaultMenuModel;
import org.primefaces.model.menu.DefaultSubMenu;
import org.primefaces.model.menu.MenuModel;

@ManagedBean(name = "myMenuBean")
@SessionScoped
public class MyMenuBean implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private MenuModel model;
	DefaultMenuItem item = new DefaultMenuItem("External");
	DefaultMenuItem item2 = new DefaultMenuItem("Photoshop");
	DefaultMenuItem item3 = new DefaultMenuItem("Coda");
	DefaultMenuItem item4 = new DefaultMenuItem("Safari");
	DefaultMenuItem item5 = new DefaultMenuItem("Finder");
	DefaultMenuItem item6 = new DefaultMenuItem("Uploader");
	

	public MyMenuBean() {
		model = new DefaultMenuModel();
		// first menu item
		// DefaultMenuItem item = new DefaultMenuItem("External");
		item.setUrl("/pages/mycontent1.jsf");
		item.setIcon("/images/stack/aperture.png");
		//item.setCommand("#{myMenuBean.click}");
		item.setCommand("#{menuBean.save}");
		model.addElement(item);

		// DefaultMenuItem item2 = new DefaultMenuItem("Photoshop");
		item2.setUrl("/pages/mycontent2.jsf");
		item2.setIcon("/images/stack/photoshop.png");
		item2.setCommand("#{myMenuBean.click2}");
		model.addElement(item2);

		// DefaultMenuItem item3 = new DefaultMenuItem("Coda");
		item3.setUrl("/pages/mycontent3.jsf");
		item3.setIcon("/images/stack/coda.png");
		item3.setCommand("#{myMenuBean.click3}");
		model.addElement(item3);

		// DefaultMenuItem item4 = new DefaultMenuItem("Safari");
		item4.setUrl("/pages/mycontent4.jsf");
		item4.setIcon("/images/stack/safari.png");
		item4.setCommand("#{myMenuBean.click4}");
		model.addElement(item4);

		// DefaultMenuItem item5 = new DefaultMenuItem("Finder");
		item5.setUrl("/pages/mycontent5.jsf");
		item5.setIcon("/images/stack/finder.png");
		item5.setCommand("#{myMenuBean.click5}");
		model.addElement(item5);
		
		// DefaultMenuItem item6 = new DefaultMenuItem("Uploader");
		item6.setUrl("/pages/mycontent6.jsf");
		item6.setIcon("/images/stack/Upload.png");
		item6.setCommand("#{myMenuBean.click6}");
		model.addElement(item6);
		
		

	}

	public MenuModel getModel() {
		return model;
	}

	public void click() {
		// addMessage("Data saved");
		System.out.println("Into click()");
		this.item.setStyle("#{uiHelperBean.getViewId() == '/pages/mycontent1.xhtml' ? 'font-size: 20px;font-style:italic;' : ''}");
		this.item2.setStyle(null);
		this.item3.setStyle(null);
		this.item4.setStyle(null);
		this.item5.setStyle(null);
		
		

	}

	public void click2() {
		// addMessage("Data saved");
		System.out.println("Into click2()");
		this.item2.setStyle("#{uiHelperBean.getViewId() == '/pages/mycontent2.xhtml' ? 'font-size: 20px;font-style:italic;' : ''}");
		this.item.setStyle(null);
		this.item3.setStyle(null);
		this.item4.setStyle(null);
		this.item5.setStyle(null);

	}

	public void click3() {
		// addMessage("Data saved");
		System.out.println("Into click3()");
		this.item3.setStyle("#{uiHelperBean.getViewId() == '/pages/mycontent3.xhtml' ? 'font-size: 20px;font-style:italic;' : ''}");
		this.item.setStyle(null);
		this.item2.setStyle(null);
		this.item4.setStyle(null);
		this.item5.setStyle(null);

	}

	public void click4() {
		// addMessage("Data saved");
		System.out.println("Into click4()");
		this.item4.setStyle("#{uiHelperBean.getViewId() == '/pages/mycontent4.xhtml' ? 'font-size: 20px;font-style:italic;' : ''}");
		this.item.setStyle(null);
		this.item3.setStyle(null);
		this.item2.setStyle(null);
		this.item5.setStyle(null);

	}

	public void click5() {
		// addMessage("Data saved");
		System.out.println("Into click5()");
		this.item5.setStyle("#{uiHelperBean.getViewId() == '/pages/mycontent5.xhtml' ? 'font-size: 20px;font-style:italic;' : ''}");
		this.item.setStyle(null);
		this.item3.setStyle(null);
		this.item4.setStyle(null);
		this.item2.setStyle(null);

	}

	public void update() {
		addMessage("Data updated");
	}

	public void delete() {
		addMessage("Data deleted");
	}

	public String redirect() {
		return "home?faces-redirect=true";
	}

	public void addMessage(String summary) {
		FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, null);
		FacesContext.getCurrentInstance().addMessage(null, message);
	}
}